<template>
	<view class="address-select-page">
		<scroll-view scroll-y="true">
			<view class="address-title">
				<text>当前定位城市</text>
			</view>
			<view class="address-item">
				<text class="iconfont icon-dingweiweizhizuobiaoxianxing mr-1" style="color: #999999;font-size: 44upx;"></text>
				<text class="addtext">{{currentCity.name}}</text>
			</view>
			<view class="address-title">
				<text>选择城市</text>
			</view>
			<view v-for="(item,index) in cityList" :key="index" class="address-item" @tap="switchCity(item)">
				<text>{{item.name}}</text>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import api from '@/common/lib/request.js';
	export default {
		data() {
			return {
				cityList: [],
				currentCity: {
					name: '全国',
					id: 1
				}
			};
		},
		onLoad() {
			this.initCityList()
		},
		methods: {
			initCityList() {
				const _this = this;
				let locationInfo = uni.getStorageSync('location');
				this.currentCity = JSON.parse(locationInfo);
				api.request({
						url: '/site/list',
						data: {}
					})
					.then(response => {
						console.log(response);
						_this.cityList = response.length > 0? response:[];
					})
					.catch(err => {
						console.log(err);						
					});
			},
			switchCity(item){
				console.log(item)
				this.currentCity = item;
				uni.setStorage({
					key: 'location',
					data: JSON.stringify(item)
				});
				uni.navigateBack({
					
				})
			}
		}
	}
</script>

<style lang="scss">
	.address-select-page {
		.address-title {
			height: 90upx;
			display: flex;
			align-items: center;
			background-color: #F3F3F3;
			font-size: 24upx;
			color: #999999;
			text-indent: 30upx;
		}
		.address-item{
			height: 110upx;
			width: 720upx;
			padding-left: 30upx;
			display: flex;
			align-items: center;
			font-size: 34upx;
			border-bottom: 1px solid #EEEEEE;
		}
	}
</style>
